package main

func maxSubArray(nums []int) int {
	n := len(nums)

	maxCurr := nums[0]
	maxSum := nums[0]

	for i := 1; i < n; i++ {
		maxCurr += nums[i]
		if maxCurr < nums[i] {
			maxCurr = nums[i]
		}
		if maxCurr > maxSum {
			maxSum = maxCurr
		}
	}

	return maxSum
}
